package com.cntaiping.royal.bass.core.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.cntaiping.royal.bass.core.entity.SysUser;
import com.cntaiping.royal.bass.core.entity.UserEntity;
import com.cntaiping.royal.bass.core.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@RestController
public class UserController {
	@Autowired
	private UserService userService;
	
	/**
	 * @param sEcho 不知道是什么 写着放这里  null
	 * @param start  当前页
	 * @param length 显示多少条
	 * @param extra_search 条件查询
	 * @return
	 */
	@RequestMapping("/userlist")
	public Map<String,Object> queryList(Integer sEcho,Integer start,Integer length,String extra_search){
		   PageHelper.startPage(start, length);
		    List<UserEntity> list = userService.queryList(extra_search);
	        PageInfo<UserEntity> appsPageInfo = new PageInfo<>(list);
	        Map<String, Object> map = new HashMap<String, Object>();
	        map.put("sEcho", sEcho);  
	        map.put("iTotalRecords", appsPageInfo.getTotal());  
	        map.put("iTotalDisplayRecords", appsPageInfo.getTotal());  
	        map.put("data", list);  
          return map;  
        
	}
	
    @RequestMapping(value = "/querySysUser", produces = { "application/json;charset=UTF-8" })
     public SysUser querySysUser(String username){
	    return userService.findByUserName(username);
	    }

    @RequestMapping("/queryUser")
    public UserEntity queryUserEntity(long userId){
        UserEntity userEntity=userService.findById(userId);
        return userEntity;
    }

    @RequestMapping("/insert")
	public int insertEntity() {
        return userService.insertEntity();
	}

    @RequestMapping("/insertParam")
    public int insertParam() {
        return userService.insertParam();
    }

    @RequestMapping("/insertByMap")
    public int insertByMap() {
        return userService.insertByMap();
    }

    @RequestMapping("/updateEntity")
    public int updateEntity() {
        return userService.updateEntity();
    }

    @RequestMapping("/deleteEntity")
    public int deleteEntity() {
        return userService.deleteEntity();
    }
}
